#include "rational.h"

#include <cstddef>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;


bool test0()
{
	bool result = true;

	result &= Rational(1, 2) == Rational(21, 42);

	return result;
}

bool test1()
{
	bool result = true;

	result &= Rational(1, 2) + Rational(1, 3) == Rational(5, 6);

	return result;
}

bool test2()
{
	bool result = true;

	result &= Rational(1, 2) - Rational(1, 3) == Rational(1, 6);

	return result;
}

bool test3()
{
	bool result = true;

	result &= Rational(1, 2) * Rational(7, 4) == Rational(7, 8);

	return result;
}

bool test4()
{
	bool result = true;

	result &= Rational(25, 16) / Rational(17, 3) == Rational(75, 272);

	return result;
}

bool test5()
{
	bool result = true;

	result &= ! (Rational(25, 16) != Rational(250, 160));
	result &= Rational(25, 16) != Rational(17, 3);

	return result;
}

bool test6()
{
	bool result = true;

	result &= ! (Rational(25, 16) > Rational(250, 160));
	result &= Rational(25, 16) < Rational(17, 3);
	result &= Rational(17, 3) > Rational(25, 16);
	result &= ! (Rational(17, 3) > Rational(17, 3));

	return result;
}

bool test7()
{
	bool result = true;

	result &= Rational(25, 16) >= Rational(250, 160);
	result &= Rational(25, 16) >= Rational(23, 17);
	result &= Rational(17, 3) <= Rational(18, 2);

	return result;
}

bool test8()
{
	bool result = true;

	Rational inst(1, 2);
	result &= ++inst == Rational(3, 2);
	result &= inst++ == Rational(3, 2);
	result &= inst == Rational(5, 2);

	result &= --inst == Rational(3, 2);
	result &= inst-- == Rational(3, 2);
	result &= inst == Rational(1, 2);

	return result;
}

bool test9()
{
	bool result = true;

	result &= 5/3. - Rational(5, 3) < 1e-6;

	return result;
}

bool test10()
{
	bool result = false;

	try { Rational(5, 0); }
	catch (std::invalid_argument)
	{
		result = true;
	}

	return result;
}

bool (*tests[])() = {test0, test1, test2, test3, test4, test5, test6, test7, test8, test9, test10, NULL};

int main()
{
	for (int i = 0; tests[i] != NULL; i++)	cout << "Test #" << i << (tests[i]() ? " passed" : " failed") << endl;
}
